class_name BlockGranterEffect
extends Effect

# 通用护甲给予效果 - 可以被多个卡牌复用
# 功能：基于记录的伤害值给予护甲

# 配置参数
var record_key: String = ""  # 记录键，用于获取对应的伤害记录
var turn_used: int = -1      # 记录卡牌使用时的回合数
var block_multiplier: float = 1.0  # 护甲倍数（默认1.0，即1:1）

func execute(targets: Array[Node]) -> void:
	print("🛡️ BlockGranterEffect: 开始给予护甲，记录键=%s" % record_key)
	
	if targets.size() == 0:
		print("❌ 没有目标")
		return
	
	var player = targets[0]
	if not player or not player.stats:
		print("❌ 无效的玩家目标")
		return
	
	# 获取记录的伤害值
	var recorded_damage = DamageRecorderEffect.get_recorded_damage(record_key, turn_used)
	var final_block = int(recorded_damage * block_multiplier)
	
	if final_block > 0:
		# 给予护甲
		player.stats.gain_block(final_block)
		print("🛡️ BlockGranterEffect: 给予护甲 %d (基于记录伤害 %d × 倍数 %.1f)" % [final_block, recorded_damage, block_multiplier])
		
		# 清理记录的伤害值
		DamageRecorderEffect.clear_recorded_damage(record_key, turn_used)
	else:
		print("🛡️ BlockGranterEffect: 没有记录到伤害，护甲值为0")
	
	print("🔄 BlockGranterEffect: 护甲给予完成")


# 配置方法：设置护甲给予参数
func configure(key: String, turn: int, multiplier: float = 1.0) -> void:
	record_key = key
	turn_used = turn
	block_multiplier = multiplier
	print("⚙️ BlockGranterEffect: 配置完成 - 记录键=%s, 回合=%d, 倍数=%.1f" % [record_key, turn_used, block_multiplier]) 